package com.yingxue.lesson.controller;

import com.yingxue.lesson.entity.User;
import com.yingxue.lesson.service.UserCacheService;
import com.yingxue.lesson.service.UserService;
import com.yingxue.lesson.vo.req.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author gusheng
 * @Date 2021/1/6 16:02
 * @ClassName 类名称
 * @Description 类描述
 * @Version 3.4
 */

@Api(description = "用户接口,cache测试")
@RestController
@RequestMapping("/user")
public class UserCacheTestController {

    @Autowired
    private UserCacheService userCacheService;

    @ApiOperation("单个用户查询，按userid查用户信息")
    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public UserVO findById(@PathVariable int id) {
        User user = this.userCacheService.findUserById(id);
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return userVO;
    }

    @ApiOperation("修改某条数据")
    @PostMapping(value = "/updateUser")
    public void updateUser(@RequestBody UserVO obj) {
        User user = new User();
        BeanUtils.copyProperties(obj, user);
        userCacheService.updateUser(user);
    }

    @ApiOperation("创建某条数据")
    @PostMapping(value = "/addUser")
    public void addUser(@RequestBody UserVO obj) {
        User user = new User();
        BeanUtils.copyProperties(obj, user);
        userCacheService.createUser(user);
    }


    @ApiOperation("按id删除用户")
    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
    public void deleteUser(@PathVariable int id) {
        this.userCacheService.deleteUser(id);
    }

}
